class Solution
{
public:
    vector<int> decrypt(vector<int> &code, int k)
    {
        int n = code.size();
        if (k == 0)
        {
            return vector<int>(n, 0);
        }
        int kSum = 0;
        vector<int> result(n);
        if (k > 0)
        {
            for (int i = 0; i < k; ++i)
            {
                kSum += code[i];
            }
            for (int i = 0; i < n; ++i)
            {
                kSum = kSum - code[i] + code[(i + k) % n];
                result[i] = kSum;
            }
        }
        else
        {
            k = -k;
            for (int i = n - 1; i >= n - k; --i)
            {
                kSum += code[i];
            }
            for (int i = n - 1; i >= 0; --i)
            {
                kSum = kSum - code[i] + code[(i - k + n) % n];
                result[i] = kSum;
            }
        }
        return result;
    }
};